<?php


namespace app\common\service\companyIndustry\realtime;

use app\common\service\BaseService;
use app\common\service\MongoService;

/**
 * 供浆量（脱硫）
 * MongoDB的SQL语句如下
 */
class SulfurSlurrySupplyService extends BaseService
{
    /**
     * （减排前）脱硫供浆量
     * @param integer $facilityId 设施ID
     * @param string $planNumber 预案编号
     * @return mixed
     * @throws \Exception
     * @throws \MongoDB\Driver\Exception\Exception
     * @author hongwei 2019-07-22
     */
    public function singleCompanySingleDrainSingleFacility($facilityId, $planNumber)
    {
        $mongo      = new MongoService();
        $data       = $mongo->getBeforeSulfurSlurrySupplyFieldOfHourAvg($facilityId, $planNumber);
        if (!$data) {
            exception('无数据，查看是否是脱硫设备！');
        }
        return sprintf('%.3f',$data);
    }

    /**
     * 测试所用,这里用作在 navicat 使用
     * @return string
     * @author hongwei 2019-07-22
     */
    public function mongoAboutSql()
    {
        //查询供浆量
        $sql = <<<EOT
db.company_industry_monitor_sulfur_minute.aggregate([
    {
        $match: {
        facility_id: 3,
            "publish_time": {
                $gte: "2019-06-26 00:00:00",
                $lte: "2019-07-02 23:59:59",

            },
            "export_smoke_dust": {
                $ne: - 1
            },
            "emissions": {
                $ne: - 1
            }, //排放量不为-1

        }
    },
    {
        $group: {
        _id: {
            "facility_id": "$facility_id"
            },
        pulp_supply: {
            $sum: "$pulp_supply"
            },

    }
    },
]);
EOT;
        return $sql;
    }
}